<?
	$_SESSION['url'] = getURL();
	
	if(isset($_GET['u_id'])){
		$u_id = intval($_GET['u_id']);
	}else{
		reHome($urlHome);
	}
	
	if(isset($_GET['nganh'])){
		$nganh = intval($_GET['nganh']);
	}else{
		$nganh = '-1';
	}
	
	function getStatus($pid,$type){
		global $db,$prefix;
		$status = 0;
		$rs = $db->query("SELECT * FROM ".$prefix."sanpham WHERE t_id = '".$pid."'");
		$row = $db->fetch_array($rs);
		if($type == 0){
			$status = $row[t_noibat];
		}else{
			$status = $row[t_hienthi];
		}
		return $status;
	}
	
	if(isset($_GET['act'])){
		
		if($_SESSION['uid'] == $u_id){
			$act = $_GET['act'];
			if(isset($_GET['pid'])){
				$pid = intval($_GET['pid']);	
			}else{reHome($urlHome);}
			
			$sta = 0;
			if($act == "noibat"){
				if(getStatus($pid,0) == 1){
					$sta = 0;
				}else{
					$sta = 1;
				}
				
				$db->query("UPDATE ".$prefix."sanpham SET t_noibat = '".$sta."' WHERE t_id = '".$pid."'");
			}else{
				if(getStatus($pid,1) == 1){
					$sta = 0;
				}else{
					$sta = 1;
				}
				
				$db->query("UPDATE ".$prefix."sanpham SET t_hienthi = '".$sta."' WHERE t_id = '".$pid."'");
				
			}
			header("Location: ".$root."/san-pham/".$u_id."/".tenNguoiDung2($u_id)."");
		}else{reHome($urlHome);}
	}
	
?>
<div id="linkPath">
<div class="linkPath">
    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>

    </div>
    <div class="corner-round-01-body">    
        
		<?
			file_exist('includes/inc_thong_tin_rieng.php');
			include('includes/inc_thong_tin_rieng.php');	
		?>
		
        <div style="clear: both;"></div>

    </div>
    <div class="corner-round-01-bottom-right">
        <div class="corner-round-01-bottom-left">
            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>    
    </div>
    <!-- Main Page-Content { -->    
    <div id="page-content">    
         <div id="ctl00_idMainHolder_idListPanel">

	   
            <div id="page-content-lpane">                        
                
<!-- Menu Left { -->
<div id="menuleft" class="menucategory">
    <div class="category-header-right menucategory">
        <div class="category-header-left">
            <div class="category-header-bg" style="text-align:left;padding-left:10px">
                <p>Ngành hàng</p>
            </div>
        </div>

    </div> 
    <div class="corner-round-05-top-right"><div class="corner-round-05-top-left"><div class="corner-round-05-top-bg"></div></div></div>
    <div class="corner-round-05-body">        
        <div id="product-category">            
            
                    <div style="padding-top:5px;"></div>
                    <div class="category-items-filters"><span><a href="<?=$root?>/nganh-san-pham/<?=$u_id?>/0/<?=$myString->vietdecode('Sản phẩm nổi bật')?>" <? if($nganh == 0){?> style="color:#DA5100;" <? }?>>Sản phẩm nổi bật</a></span></div>
            <?
				$sql = "SELECT * FROM ".$prefix."sanpham WHERE t_nguoidang = '".$u_id."'";
				
				if($_SESSION['uid'] != $u_id){ $sql .= " AND t_hienthi = 1"; }
				
				$rs = $db->query($sql);
				$arrList = "";
				$st = 0;
				while($row = $db->fetch_array($rs)){
					$st++;
					if($st != $db->num_rows($rs)){
						$arrList .= $row[t_loaisanpham] . ",";
					}else{
						$arrList .= $row[t_loaisanpham];
					}
				}
				if($arrList != ""){
					$rs = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_id IN(".$arrList.") AND c_hienthi = 1");
					while($row = $db->fetch_array($rs)){
					$c_ten = stripslashes($row[c_ten]);
					$c_id = $row[c_id];
				?>    
						<div class="category-items-filters">
							<span><a href="<?=$root?>/nganh-san-pham/<?=$u_id?>/<?=$c_id?>/<?=$myString->vietdecode($c_ten)?>" <? if($nganh == $c_id){?> style="color:#DA5100;" <? }?>><?=$c_ten?></a></span>                                
						</div>            
					<? } ?>
				
				<? } ?>
                              
                  
            <div style="height:5px;"></div>               
        </div>        
    </div>

    <div class="corner-round-05-bottom-right">
        <div class="corner-round-05-bottom-left">
            <div class="corner-round-05-bottom-bg"></div>
        </div>
    </div>    
</div>
<!-- } Menu Left -->
 <script language="javascript">
  	function funSapXep(id,u_id,nganh,p){
		window.location='<?=$root?>/?mod=sanpham&u_id=' + u_id + '&nganh=' + nganh + '&p=' + p + '&sid=' + id;
	}
  </script>   
                 
            </div>
            <div id="page-content-mpane-all">                     
<?
	//				
					if($nganh == '-1'){
						$sql = "SELECT * FROM ".$prefix."sanpham WHERE 1";
					}else if($nganh == 0){
						$sql = "SELECT * FROM ".$prefix."sanpham WHERE t_noibat = 1";
					}else{
						$sql = "SELECT * FROM ".$prefix."sanpham WHERE t_loaisanpham = '".$nganh."'";
					}
					
					if($_SESSION['uid'] != $u_id){
						$sql .= " AND t_hienthi = 1";					
					}
					
					$sql .= " AND t_nguoidang = '".$u_id."'";
					
					if(isset($_GET['sid'])){
						$sid = intval($_GET['sid']);
						if($sid == 1){
							$sql .= " ORDER BY t_id DESC";
						}else if($sid == 2){
							$sql .= " ORDER BY t_id DESC";
						}else if($sid == 3){
							$sql .= " ORDER BY t_giaban ASC";
						}else if($sid == 4){
							$sql .= " ORDER BY t_giaban DESC";
						}else{
							$sql = $sql;
						}
					}
					///////Paging
						$pp=10; 
						$parr=array();
						$parr=paging($sql,$pp);
						$page=$parr[0];
						$limitvalue=$parr[1];
						$numofpages=$parr[2];
						$sql.=" LIMIT $limitvalue, $pp";
						
					 $rs = $db->query($sql);
?>               
<div id="filtersDescription">

    <div class="corner-round-04-top-right">
        <div class="corner-round-04-top-left">
            <div class="corner-round-04-top-bg"></div>
        </div>
    </div>
    <div class="corner-round-04-body">         
        <ul id="descriptionBar" style="margin:0px;">
            <li style="float:left;margin:0px;line-height:20px;">
                Tìm thấy <b><?=$db->num_rows($rs)?></b> sản phẩm.
            </li>

            <li style="float:right;margin:0px;line-height:20px;" id="menuContainer">                                 
                Sắp xếp theo: 
				<select name="sapxep" id="sapxep" onchange="funSapXep(this.value,'<?=$u_id?>','<?=$nganh?>','<?=$p?>');">
					<option value="0" <? if($sid==0){?> selected="selected" <? }?>>--- Tất cả ---</option>
					<option value="1" <? if($sid==1){?> selected="selected" <? }?>>Mới cập nhật</option>
					<option value="2" <? if($sid==2){?> selected="selected" <? }?>>Mới đăng bán</option>
					<option value="3" <? if($sid==3){?> selected="selected" <? }?>>Giá tăng dần</option>
					<option value="4" <? if($sid==4){?> selected="selected" <? }?>>Giá giảm dần</option>
				</select>                
            </li>    
        </ul>
        <br class="clearBoth" style="font-size:0pt;"/>
        <p>
            
        </p> 
    </div>

    <div class="corner-round-04-bottom-right">
        <div class="corner-round-04-bottom-left">
            <div class="corner-round-04-bottom-bg"></div>
        </div>
    </div>   
</div>
<!-- Product List { -->
<div id="ctl00_idMainHolder_idProductList_idListPanel">
		
    <div id="product-list">
        <div id="product-list-header">       
            <div class="product-col product-col-name">

                <p>Tên sản phẩm</p>
            </div>
            <div class="product-col product-col-price">
                <p>Giá</p>
            </div>
            <div class="product-col product-col-region">
                <p>Phạm vi bán</p>

            </div>
        </div>
        <div style="clear:both;height:4px;font-size:0pt;"></div>
        <div id="product-list-body">
            <div class="corner-round-05-top-right">
                <div class="corner-round-05-top-left">
                    <div class="corner-round-05-top-bg"></div>
                </div>
            </div>

            <div class="corner-round-05-body2">            
                <div id="products-list" style="height:auto;overflow:hidden">    
                    
                           
				<?
					//
					$st = 0;
					while($row = $db->fetch_array($rs)){
					$st++;
					
					$t_id = $row[t_id];	
					$t_nguoidang = $row[t_nguoidang];
					$t_ten_nguoidang = tenNguoiDung($t_nguoidang);
					$t_tieude = $myString->unQuote(stripslashes($row[t_tieude]));
					$t_hinhanh = $PathThumbFile . $row[t_hinhanh];
					$t_mota = $myString->unQuote(stripslashes($row[t_mota]));
					$t_giaban = showprice($row[t_giaban]);
					$t_loaitien = loadLoaiTien($row[t_loaitien]);		
					$t_tinhthanh = layTinhThanh($row[t_tinhthanh]);
					$t_solanxem = $row[t_solanxem];
					$t_noibat = $row[t_noibat];
					$t_hienthi = $row[t_hienthi];
					$t_xemgannhat = format_date_time($row[t_xemgannhat]);
					$comment = loadSoComment($t_id);
				?>		   
						   
						    <div class="product-item-rows">
                               <ul>
                                    <li class="product-item-col-picture">
                                        <p> 
                                            <a title="<?=$t_tieude?>" href="<?=$root?>/chi-tiet-san-pham/<?=$t_id?>/<?=$myString->vietdecode($t_tieude)?>" class="tips product-name">
                                                <img width="100px" style="vertical-align:middle" alt="<?=$t_tieude?>" src="<?=$root?>/<?=$t_hinhanh?>" onerror="this.src='<?=$root?>/themes/images/noimg.jpg';"/>
                                            </a>
                                        </p>                     
                                    </li>

                                    <li class="product-item-col-name">
                                        <h1>
                                            <a href="<?=$root?>/chi-tiet-san-pham/<?=$t_id?>/<?=$myString->vietdecode($t_tieude)?>" class="product-name" title="<?=$t_tieude?>"><?=$t_tieude?></a>
                                        </h1> 
                                        <p class="truncate" style="text-align:left;">
                                            <?=$t_mota?>
                                        </p>        
                                         <p style="padding-bottom:5px;">
                                         
                                        </p> 
                                        <p style="font-size:8pt;color:Gray;">
                                            <?=$t_xemgannhat?> | Xem: <?=$t_solanxem?> | Comments: <?=$comment?>
                                        </p> 
								<?
									if($_SESSION['uid'] == $u_id){
								?>  
                                        <div style="margin-top: 10px; margin-left:10px;">
                                                <input value="1" type="checkbox" <? if($t_noibat == 1){ ?> checked="checked" <? }?> onclick="javascript:window.location='<?=$root?>/?mod=sanpham&u_id=<?=$u_id?>&pid=<?=$t_id?>&p=<?=$p?>&sid=<?=$sid?>&act=noibat';"> <label>Nổi bật</label> | 
                                                <input value="1" type="checkbox" <? if($t_hienthi == 0){ ?> checked="checked" <? }?> onclick="javascript:window.location='<?=$root?>/?mod=sanpham&u_id=<?=$u_id?>&pid=<?=$t_id?>&sid=<?=$sid?>&p=<?=$p?>&act=hienthi';"> <label>Tạm ẩn</label> |                                                 
                                                <a href="<?=$root?>/chi-tiet-san-pham/<?=$t_id?>/<?=$myString->vietdecode($t_tieude)?>">Xem</a> | 
                                                <a href="javascript: void(0);" onclick="javascript: window.location='<?=$root?>/sua-san-pham/<?=$t_id?>/<?=$myString->vietdecode($t_tieude)?>';">Cập nhật</a> | 
                                                <a href="javascript:void(0);" onclick="confirmDelete('<?=$root?>/action.php?act=del_sanpham&u_id=<?=$u_id?>&id=<?=$t_id?>');">Xóa</a>
                                          </div>
								<? } ?>
                                    </li>
                                    <li class="product-item-col-price">
                                        <p>
                                            <?=$t_giaban?>&nbsp;<?=$t_loaitien?>                                        
                                        </p>
                                    </li>
                                    <li class="product-item-col-region">
                                        <p>
                                            <a href="javascript:void(0)"><?=$t_tinhthanh?></a> 
                                        </p>
                                    </li>
                                </ul>                                                       
                            </div>  
                            <?
								if($st != $db->num_rows($rs)){
							?>
                                <div class="product-list-sep">&nbsp;</div>                         
								
							<? } ?>
                            
                     <? }
					  if($db->num_rows($rs) == 0){
						  echo "<p align=\"center\">Chưa có sản phẩm nào !</p>";
					  }
					  ?>       
                                                         
                </div>
            </div>
            <div class="corner-round-05-bottom-right">
                <div class="corner-round-05-bottom-left">
                    <div class="corner-round-05-bottom-bg"></div>
                </div>
            </div>    
        </div>

        <div id="product-list-footer"></div>
    </div>
    <p align="center" class="font">
			<?php echo page_div( "".$root."/?mod=sanpham&u_id=".$u_id."&nganh=".$nganh."&sid=".$sid."&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	</p>
	<br /><br />
    <!-- } Product List -->

	</div>

                  
            </div>  
        
</div>
                         
    </div>
    <div style="clear:both;"></div>      
    <!-- } Main Page-Content -->  

                
            </div>
